<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   文章
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('article');
$ctable = Table('article_cate');

if($a == 'view')
{
	$id = intval($_GET['id']);
	!$id && ShowMsg('查看的信息不存在！',MU());

	$data = $db->getrow('SELECT t.*,c.title AS cname FROM '.$table.' t LEFT JOIN '.$ctable.' c ON t.cid = c.id WHERE t.id = '.$id.' AND t.status = 1');
	!$data && ShowMsg('查看的信息不存在！',MU());
	
	$tpl->display('wap/article_view');
	exit;
}

$id = intval($_GET['id']);
!$id && ShowMsg('查看的信息不存在！',MU());

$cate = $db->getrow('SELECT * FROM '.$ctable.' WHERE id = '.$id);
!$cate && ShowMsg('查看的信息不存在！',MU());

$data  = [];
$where = ' FROM '.$table.' t WHERE t.status = 1 AND t.cid = '.$id;

$title = NoBadStr($_GET['title']);
$title && $where .= ' AND t.title LIKE \'%'.$title.'%\'';

$page = max(1,intval($_GET['page']));
$size = 20;

$tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
if($tmp['p'])
{
	$limit = ' LIMIT '.($page - 1) * $size.','.$size;

	$url = MU($c.'/'.$a,['id'=>$id,'title'=>$title]);
	$orderby = ' ORDER BY t.id DESC ';
	
	$data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
	
	//$multi = Multi($url,$page,$tmp['p'],$size);
}

$tpl->display('wap/article'.(in_array($id,[3,9,4]) ? '_notice' : ''));